import { actionTypes} from "../actions/actionTypes";

const userInfo = {
    isLogin: Boolean(JSON.parse(window.localStorage.getItem('isUserLogin')))||Boolean(JSON.parse(window.sessionStorage.getItem('isUserLogin'))),
    isLoading: false,
    info: JSON.parse(window.localStorage.getItem('userInfo')) || JSON.parse(window.sessionStorage.getItem('userInfo'))
}

const user = (state=userInfo,action) => {
    switch (action.type) {
        case actionTypes.GetUsers:
            return Object.assign({},state,{
                info: action.data
            },{
            isLogin: true,
            isLoading: false
        });
        case actionTypes.LoadingUser: return Object.assign({},state,{
            isLoading: true
        });
        case actionTypes.ExitUser: return {
            isLogin: false,
            isLoading: false,
            info: {}
        }
        default : return state;
    }
}

export default user;
